/**
 * Created by Vasil Toshev on 12.01.14.
 */
/* global ko, calculateLinks, updateGroups  */
// AppViewModel for the UI
function AppViewModel() {
    'use strict';
    var self = this;
    self.relevanceThreshold = ko.observable(3);
    self.groupKeyValues = ko.observable(["","creator","medium"]);

    self.enableCollision = ko.observable(false);
    self.enableScreensaverMode = ko.observable(false);

    self.enableClustering = ko.observable(false); //whether groups should cluster together
    self.selectedGroupKey = ko.observable(""); //the attribute that nest() uses to group elements
    self.enableGrouping = ko.observable(false); //is grouping enabled
    self.groupsRollup =  ko.observableArray([]);

    self.relevanceFlagAssociation = ko.observable(true);
    self.relevanceFlagSubject = ko.observable(true);
    self.relevanceFlagAtmosphere = ko.observable(true);
    self.relevanceFlagEmotion = ko.observable(true);
    self.relevanceFlagMainMotive = ko.observable(true);
    self.relevanceFlagCreator = ko.observable(true);

    // use a computed observable to get notified if any checkbox changes state
    // in order to calculate the links anew
    ko.computed(function(){
        self.relevanceFlagAssociation();
        self.relevanceFlagSubject();
        self.relevanceFlagAtmosphere();
        self.relevanceFlagEmotion();
        self.relevanceFlagMainMotive();
        self.relevanceFlagCreator();
        calculateLinks();
    });
    ko.computed(function(){
        self.selectedGroupKey();
        updateGroups();
        if(self.selectedGroupKey()===""){
            self.enableClustering(false);
        }
    });

    self.colorScale = ko.observableArray(["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"]);
}

var myAppViewModel = new AppViewModel();

// Activates knockout.js
ko.applyBindings(myAppViewModel);